<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}"
	rel="stylesheet" />
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-add">
			<div class="form-group">
				<label class="col-sm-3 control-label ">名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="name" id="name" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">微信号：</label>
				<div class="col-sm-8">
					<select class="form-control code_id" name="codeId"  th:with="wxCodes=${codes}">
						<option value="">选择微信号</option>
						<option th:each="code : ${wxCodes}" th:text="${code.wxName}" th:value="${code.wxId}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">模板：</label>
				<div class="col-sm-8">
					<select class="form-control model_id"  name="modelId" th:with="templates=${templates}">
						<option value="">选择模板</option>
						<option th:each="template : ${templates}" th:text="${template.modelName}" th:value="${template.id}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">方法名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="methodName" id="methodName" value="sendWxMsg" readonly="true">
				</div>
			</div>

		</form>
	</div>
	<div th:include="include::footer"></div>
	<script
		th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script type="text/javascript">

        $("#form-role-add").validate({
            rules:{
                name:{required:true,},
                codeId:{required:true,},
                modelId:{required:true,},
            },
            messages: {}
        });

		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
		function add() {

			var name = $("input[name='name']").val();
            var codeId = $(".code_id option:selected").val();
			var modelId = $(".model_id option:selected").val();
			var methodName = $("input[name='methodName']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/wxSengdingSchdule/add",
				data : {
					"name": name,
					"codeId": codeId,
					"modelId": modelId,
					"methodName": methodName
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>
